package com.project.controrller;

import com.project.bean.OrderBean;
import com.project.bean.UserBean;
import com.project.service.IOrderService;
import com.project.service.IShoppService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
@RestController
@RequestMapping("order")
public class OrderController {
    @Autowired
    private IOrderService orderService;
    @RequestMapping("add")
    public String addOrder(OrderBean order, HttpServletRequest req){
        UserBean user=(UserBean) req.getSession().getAttribute("loginUser");
        order.setUserId(user.getId());
        orderService.add(order);
        return "ok";
    }
    @RequestMapping("findByItem")
    public IPage<OrderBean> findByItem(Integer pageNO, HttpServletRequest req) {
        UserBean userBean = (UserBean) req.getSession().getAttribute("loginUser");
        return service.findByItem(pageNO, userBean.getId());
    }

    @RequestMapping("findById")
    public OrderBean findById(Integer id) {
        return service.findById(id);
    }

    @RequestMapping("manageFindByItem")
    public IPage<OrderBean> manageFindByItem(Integer pageNO, String status, LocalDate startDate, LocalDate endDate) {
        return service.manageFindByItem(pageNO, status, startDate, endDate);
    }

    @RequestMapping("send")
    public String send(Integer id) {
        service.manageSend(id);
        return "ok";
    }

    @RequestMapping("findByStatus")
    public List<OrderBean> findByStatus() {
        return service.findByStatus();
    }

    @RequestMapping("closing")
    public String closing(Integer id) {
        service.closing(id);
        return "ok";
    }
}
